namespace Stee.CAP8.MessageBus.Sagas.Core.Storages.Steps
{
    using Stee.CAP8.MessageBus.Sagas.Core.Storages.Dtos.Steps;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    /// <summary>
    /// Abstraction for a mechanism that is capable of storing saga state, retrieving it again by querying for value on the state
    /// </summary>
    public interface ISagaStepStorage
    {
        /// <summary>
        /// Finds an already-existing instance of the given saga data type that has a property with the given <paramref name="propertyName"/>
        /// whose value matches <paramref name="propertyValue"/>. Returns null if no such instance could be found
        /// </summary>
        Task<List<SagaStepDataProperty>> FindAsync(string id);

        /// <summary>
        /// Inserts the given saga data as a new instance. Throws a <see cref="ConcurrencyException"/> if another saga data instance
        /// already exists with a correlation property that shares a value with this saga data.
        /// </summary>
        Task InsertAsync(string id, SagaStepDataProperty sagaDataProperty);



        /// <summary>
        /// Deletes the saga data instance, throwing a <see cref="ConcurrencyException"/> if the instance no longer exists
        /// </summary>
        Task DeleteAsync(string id, SagaStepDataProperty sagaDataProperty);
        void Insert(string id, SagaStepDataProperty sagaDataProperty);
        List<SagaStepDataProperty> Find(string id);
    }
}
